define([
    "UtilDir/util",
    "UtilDir/tool",
    "UtilDir/combotree",
    "UtilDir/dialog",
    "UtilDir/searchBlock",
    "HomeDir/js/router",
    "HomeDir/js/tabs",
    "FwDir/util/js/bootstrap-select",
    "EasyUI", "EasyUI-lang"
], function (Util, Tool, Combotree, Dialog, SearchBlock, Router, Tabs) {

    var sysPath = getServer() + "/static/app/fwsjcj";
    var auditFormHtml = sysPath + "/siftdata/views/censusForm.html";
    var getDataController = function () {
        return getServer() + "/fw/structure";
    };
    var getDivisionController = function () {
        return getServer() + "/platform/org/divisions/";
    };
    /**
     * 页面初始化
     */
    var init = function () {
        initSearchBlock();
        queryBtnBind();
        // createAuditGrid();
        createAuditGrid();
        createProvince();
        initSearchForm();
        clickTabs();
        Util.preventclick("taskName");
        //getUser()
    };
    var user = ''
    var getUser = function () {
        $.ajax({
            url: getServer() + "/fw/taskForm/user/division",
            contentType: "application/json",
            type: "get",
            success: function (data) {
                console.log(data.message)
                user = data.message
            }
        });
    }
    var initSearchBlock = function () {
        SearchBlock.init("searchBlock");
    };
    var queryBtnBind = function () {
        $("#btnSearch").click(function () {
            // createAuditGrid();
//          console.log($('#province').combobox('getText'))
//          console.log($('#city').combobox('getText'))
//          console.log($('#county').combobox('getText'))
            createAuditGrid($('#province').combobox('getText'), $('#city').combobox('getText'), $('#county').combobox('getText'));
        });
        $("#btnReset").click(function () {
            $("#taskName").val("");
            $("#status").val("");
            $("#structureType").val("");
            $('#province').combobox('clear');
            $('#city').combobox('loadData', {}); //清空option选项
            $('#city').combobox('clear');
            $('#county').combobox('loadData', {}); //清空option选项
            $('#county').combobox('clear');
            $("#objectAnalysis").combobox("clear");
        });
        $("#btnNumbers").click(function () {
            //所属任务
            let taskName= $("#taskName").val();
            //数据状态
            let status = $("#status").val();
            //建筑物类别
            let structureType = $("#structureType").val();
            //if (user == '超级管理员') {
               // window.location.href = getServer() + "/fw/structure/exportForBuildingCount?belongtoProvince=" + $('#province').val()+"&belongtoCity="+$('#city').val() +
               //     "&belongtoArea="+ $('#county').val()+"&taskName="+taskName+"&status="+status+"&structureType="+structureType;
            window.location.href = getServer() + "/fw/structure/exportForBuildingCount";

            //} else if (user == '省级管理员') {
               // window.location.href = getServer() + "/fw/structure/export?type=" + ;
            //}
            //window.location.href = getServer() + "/fw/structure/export?type=" + ;
        })
        $("#btnAreas").click(function () {
            // if (user == '超级管理员') {
            //     console.log('user superadmin')
            //     // todo
            //     // window.location.href = getServer() + "/fw/structure/export?type=" + ;
            // } else if (user == '省级管理员') {
            //     console.log('user provinceadmin')
            //     // todo
            //     // window.location.href = getServer() + "/fw/structure/export?type=" + ;
            // }
            window.location.href = getServer() + "/fw/structure/exportForBuildingArea";
        })
    };
    var createAuditGrid = function (belongtoProvince, belongtoCity, belongtoArea) {
        var opts1;
        $("#auditGrid").datagrid({
            url: getDataController() + "/checkForQgSift/page",
            method: "GET",
            fitColumns: true,
            autoRowHeight: false,
            nowrap: false,
            columns: [
                [{
                        field: "ck",
                        checkbox: true
                    },
                    {
                        field: 'myNo',
                        title: '序号',
                        align: 'center',
                        width: '3%',
                        formatter: function (value, row, index) {
                            if (!opts1) {
                                opts1 = $('#auditGrid').datagrid('options');
                            }
                            return opts1.pageSize * (opts1.pageNumber - 1) + index + 1;
                        }
                    },
                    {
                        field: 'taskName',
                        title: '所属任务',
                        width: '15%',
                        align: 'center'
                    },
                    {
                        field: 'structureNum',
                        title: '样本编号',
                        width: '10%',
                        align: 'center'
                    },
                    {
                        field: 'belongtoProvince',
                        title: '所属省',
                        width: '8%',
                        align: 'center'
                    },
                    {
                        field: 'belongtoCity',
                        title: '所属市',
                        width: '8%',
                        align: 'center'
                    },
                    {
                        field: 'structureType',
                        title: '建筑物类型',
                        width: '10%',
                        align: 'center',
                        formatter: function (value) {
                            if (value == 0) {
                                return '砖混结构';
                            } else if (value == 1) {
                                return '多层钢筋混凝土结构';
                            } else if (value == 2) {
                                return '高层结构';
                            } else if (value == 3) {
                                return '工业厂房结构';
                            } else if (value == 4) {
                                return '空旷结构';
                            } else if (value == 5) {
                                return '土木结构';
                            } else if (value == 6) {
                                return '木结构';
                            } else if (value == 7) {
                                return '石结构';
                            } else if (value == 8) {
                                return '其它';
                            } else if (value == 9) {
                                return '砖木结构';
                            }
                        }
                    },
                    {
                        field: 'buildingName',
                        title: '建筑物名称',
                        width: '17%',
                        align: 'center'
                    },
                    {
                        field: 'status',
                        title: '数据状态',
                        width: '7%',
                        align: 'center',
                        formatter: function (value) {
                            if (value == 0) {
                                return '未提交';
                            } else if (value == 1) {
                                return '未审核';
                            } else if (value == 2) {
                                return '审核未通过';
                            } else if (value == 3) {
                                return '审核通过';
                            }
                        }
                    },
                    {
                        field: 'collectUser',
                        title: '数据采集人',
                        width: '6%',
                        align: 'center'
                    },
                    {
                        field: 'checkUser',
                        title: '数据审核人',
                        width: '6%',
                        align: 'center'
                    },
                    {
                        field: 'operation',
                        title: '操作',
                        width: '10%',
                        align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            // if (rowData.status == 1) {
                            //     return '<a onclick="_check(\'' + rowData.id + "','" + rowData.structureType + '\')">审核</a >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="_view(\'' + rowData.id + "','" + rowData.structureType + "','" + rowData.status + '\')">查看表单</a >';
                            // } else {
                                return '<a onclick="_view(\'' + rowData.id + "','" + rowData.structureType + "','" + rowData.status + '\')">查看表单</a >';
                            //}
                        }
                    }
                ]
            ],
            toolbar: [
            //     {
            //     iconCls: 'fa fa-plus-circle',
            //     text: "批量审核",
            //     handler: function () {
            //         batchCheck();
            //     }
            // }, {
            //     iconCls: 'fa fa-trash-o',
            //     text: "删除",
            //     handler: function () {
            //         deleteTask()
            //     }
            // }, {
            //     iconCls: 'fa fa-download',
            //     text: "导出",
            //     handler: function () {
            //         exportTask()
            //     }
            // }
            ],
            queryParams: {
                belongtoProvince,
                belongtoCity,
                belongtoArea,
                taskName: $("#taskName").val(),
                status: $("#status").val(),
                structureType: $("#structureType").val()
            },
            pagination: true,
            pageSize: 10
        });
    };
    var createProvince = function () {
        $('#province').combobox({
            url: "/app/divisions/root/subdivisions",
            method: 'get',
            editable: false, //不可编辑状态  
            cache: false,
            // panelHeight: 'auto',//自动高度适合  
            valueField: 'divisionId',
            textField: 'divisionName',
            onLoadSuccess: function (data) {
                $('#province').combobox('select', '');
            }
        });
        $("#province").combobox({
            onSelect: function (value) {
                var re = value.divisionId;
                var list = new Array();
                list.push({
                    "divisionId": "-1",
                    "divisionName": ""
                });
                if (re != null && re != '') {
                    list.push(re);
                }

                if (value.divisionName == '北京市' || value.divisionName == '天津市' || value.divisionName == '上海市' || value.divisionName == '重庆市') {
                    var division = [];
                    division.push(value);
                    $('#city').combobox('loadData', division);
                    $('#city').combobox('select', value.divisionName);

                    $('#county').combobox({
                        url: "/app/divisions/" + value.divisionId + "/subdivisions",
                        method: 'get',
                        editable: false, //不可编辑状态  
                        cache: false,
                        //panelHeight: 'auto',//自动高度适合  
                        valueField: 'divisionId',
                        textField: 'divisionName',
                        onLoadSuccess: function () {
                            $('#county').combobox('select', list[0].divisionName);
                        }
                    });
                } else {
                    $('#city').combobox({
                        url: "/app/divisions/" + value.divisionId + "/subdivisions",
                        method: 'get',
                        editable: false, //不可编辑状态  
                        cache: false,
                        // panelHeight: 'auto',//自动高度适合  
                        valueField: 'divisionId',
                        textField: 'divisionName',
                        onLoadSuccess: function () {
                            $('#city').combobox('select', list[0].divisionName);
                        }
                    });
                    createCity();
                    $('#county').combobox('loadData', {}); //清空option选项
                    $('#county').combobox('clear');
                }
            }
        });

        createCity();
        $('#county').combobox({
            data: '',
            editable: false, //不可编辑状态  
            cache: false
        });
    }
    var clickTabs = function () {
        $('#myTab').on('shown.bs.tab', function (e) {
            var tabid = $(e.target).attr('id');
            if (tabid == 'regionalBuildinglab') {
                createRegionalBuildingEcharts();
            } else if (tabid == 'structTypelab') {
                createStructTypeEcharts();
            } else if (tabid == 'ageBuildlab') {
                createAgeBuildEcharts();
            } else if (tabid == 'earthquakelab') {
                createEarthquakeEcharts();
            } else if (tabid == 'earthquakeSituationlab') {
                createEarthquakeSituationEcharts();
            } else if (tabid == 'ruralHouselab') {
                createRuralHouseEcharts();
            } else if (tabid == 'ruralEarthquakelab') {
                createRuralEarthquakeEcharts();
            } else if (tabid == 'hiddenDangerlab') {
                createHiddenDangerEcharts();
            }
        })
    }
    var createCity = function () {
        $("#city").combobox({
            onSelect: function (value) {
                var re = value.divisionId;
                var list = new Array();
                list.push({
                    "divisionId": "-1",
                    "divisionName": ""
                });
                if (re.list != null && re.list != 'null') {
                    list.push(re);
                }
                $('#county').combobox({
                    url: "/app/divisions/" + value.divisionId + "/subdivisions",
                    method: 'get',
                    editable: false, //不可编辑状态  
                    cache: false,
                    //panelHeight: 'auto',//自动高度适合  
                    valueField: 'divisionId',
                    textField: 'divisionName',
                    onLoadSuccess: function () {
                        $('#county').combobox('select', list[0].divisionName);
                    }
                });
            }
        });
    }
    var formValidator = function () {
        $("#auditForm").validate({
            rules: {
                reason: {
                    required: true
                }
            },
            messages: {
                reason: {
                    required: "审核不通过原因不允许为空!"
                }
            }
        });
    };

    // 批量审核
    var batchCheck = function () {
        var rows = $("#auditGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一条数据!");
            return;
        }
        var formId;
        for (var i = 0; i < rows.length; i++) {
            if (i == 0) {
                formId = rows[i].id;
            } else {
                formId = formId + "," + rows[i].id;
            }
        }
        // 判断所选中的数据中的状态
        for (var j = 0; j < rows.length; j++) {
            if (rows[j].status != 1) {
                Util.alert('所选数据中有不处于未审核状态的！');
                return;
            }
        }

        var slidebar = Util.slidebar({
            url: auditFormHtml,
            width: "580px",
            cache: false,
            close: true,
            afterLoad: function () {
                formValidator();
                $("#approved").on("click", function () {
                    $.ajax({
                        url: getDataController() + "/check",
                        data: JSON.stringify({
                            status: "3",
                            id: formId
                        }),
                        type: "post",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            Util.alert(data.message);
                            slidebar.close();
                            createAuditGrid();
                        }
                    });
                });
                $("#unapproved").on("click", function () {
                    var reason = $('#unapproval_reason').css('display');
                    if (reason == 'none') {
                        $('#unapproval_reason').show();
                    } else {
                        formValidator();
                        if ($("#auditForm").valid()) {
                            var reason = $('#reason').val();
                            $.ajax({
                                url: getDataController() + "/check",
                                contentType: "application/json",
                                data: JSON.stringify({
                                    id: formId,
                                    status: '2',
                                    checkOpinion: reason
                                }),
                                type: "post",
                                success: function (data) {
                                    Util.alert(data.message);
                                    slidebar.close();
                                    createAuditGrid();
                                }
                            });
                        }
                    }
                });
            }
        });
    };

    //导出
    var exportTask = function () {
        var buttons = [];
        buttons.push({
            name: '确定',
            callback: function () {
                //点击确定
                var formType = $("#formType").val();
                $.ajax({
                    url: getServer() + "/fw/structure/isEmpty",
                    data: {
                        type: formType
                    },
                    type: "get",
                    success: function (data) {
                        console.log(data);
                        if (data.message == '否') {
                            window.location.href = getServer() + "/fw/structure/export?type=" + formType;
                        } else if (data.message == '是') {
                            Util.alert('该类型数据数据为空，无法导出！');
                        } else {
                            // 未选择类型，请选择一种类型！
                            Util.alert(data.message);
                        }
                    }
                });
                dialog.hide();
            }
        });
        var dialog = Dialog({
            id: "viewTeamDialog",
            cache: false,
            title: '选择表单类型', //dialog标题
            width: "400px",
            height: "250px",
            body: '<div id="TeamGrid">' +
                '<div class="col-md-12 form-horizontal">' +
                '<div class="form-group">' +
                '<label for="formType" class="col-md-4 control-label"> </span>表单类型:</label>' +
                '<div class="col-md-8">' +
                '<select class="form-control" id="formType" name="formType" >' +
                '<option value="" disabled selected style="display:none;">请选择</option>' +
                '<option value="0">砖混结构、砖木结构</option>' +
                '<option value="1">多层钢筋混凝土结构</option>' +
                '<option value="2">高层结构</option>' +
                '<option value="3">工业厂房结构</option>' +
                '<option value="4">空旷结构</option>' +
                '<option value="5">土木结构</option>' +
                '<option value="6">木结构</option>' +
                '<option value="7">石结构</option>' +
                '<option value="8">其它</option>' +
                '</select>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>',
            buttons: buttons,
            afterOpen: function () {

            }
        });
        dialog.show();
    }

    //删除
    var deleteTask = function () {
        var rows = $("#auditGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        } else if (rows.length >= 1) {
            for (let i = 0; i < rows.length; i++) {
                if (rows[i].status != '1') {
                    Util.alert("数据状态为未审核的才能删除!");
                    return;
                }
            }
        }
        Util.confirm("是否要删除选中的表单?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";
            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: getServer() + "/fw/structure/del",
                contentType: "application/json",
                data: ids,
                type: "post",
                success: function (data) {
                    Util.alert(data.message);
                    createAuditGrid();
                }
            });
        }, function () {
            return;
        });
    }
    // 查看表单
    window._view = function (formId, category, status) {
        // var siftDataHtml = sysPath + "/siftdata/views/censusForm_city.html";
        var siftDataHtml = openForm(category);
        var slidebar = Util.slidebar({
            url: siftDataHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                $('.selectpicker').selectpicker();
                getData(formId, category, status);
                // getRole(roleId);
            }
        });
    };

    // 审核
    window._check = function (formId, category) {
        // var siftCheckDataHtml = sysPath + "/siftdata/views/censusCheckForm_city.html";
        var rowData = JSON.stringify(rowData);
        var siftCheckDataHtml = openCheckForm(category);
        var slidebar = Util.slidebar({
            url: siftCheckDataHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                formValidator();
                $('.selectpicker').selectpicker();
                getData(formId, category);
                $("#approved").on("click", function () {
                    $.ajax({
                        url: getDataController() + "/check/" + formId,
                        data: JSON.stringify({
                            status: "3",
                            id: formId,
                        }),
                        type: "post",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            Util.alert(data.message);
                            slidebar.close();
                            createAuditGrid();
                        }
                    });
                });
                $("#unapproved").on("click", function () {
                    var reason = $('#unapproval_reason').css('display');
                    if (reason == 'none') {
                        $('#unapproval_reason').show();
                    } else {
                        formValidator();
                        if ($('#auditForm').valid()) {
                            var reason = $('#reason').val();
                            $.ajax({
                                url: getDataController() + "/check/" + formId,
                                data: JSON.stringify({
                                    status: "2",
                                    checkOpinion: reason
                                }),
                                type: "post",
                                contentType: "application/json; charset=utf-8",
                                success: function (data) {
                                    $('#unapproval_reason').hide();
                                    Util.alert(data.message);
                                    slidebar.close();
                                    createAuditGrid();
                                }
                            });
                        }
                    }
                });
            }
        });
    };
    var viewFileUpload = function (fileData) {
        require(['UtilDir/fileupload/multiFileUpload'], function (MFU) {
            var attachIdData = "";
            var attachId = "";
            var fileArray = fileData.split(',');
            if (fileData.length != 0) {
                attachIdData = fileData.split(',');
            }
            var settings = {
                placeAt: "multiFileUpload",
                allowMC: false,
                fileSizeLimit: 1024 * 1024 * 1024,
                /*
                1.0.2版本新增
                extendColumn:[
                    {name:"文件分类",filed:"category",format:function(file){return file.name}},
                    {name:"备注",filed:"remark",format:function(file){return '机密'}}
                ],*/
                data: attachIdData,
                onUploadSuccess: function (file) {
                    attachId += file.attachId + ",";
                    if (fileData.length == 0) {
                        $("#detailFile").val(attachId.substr(0, attachId.length - 1));
                    } else {
                        $("#detailFile").val(fileData + "," + attachId.substr(0, attachId.length - 1));
                    }

                },
                onDeleteSavedFile: function (file) {
                    var index = fileArray.indexOf(file.attachId);
                    fileArray.splice(index, 1);
                    $("#detailFile").val(fileArray.toString());
                }
            };
            var MFUpload = MFU.init(settings);

        });
    };
    // 查看获取数据
    var getData = function (id, type, status) {
        $.ajax({
            url: getDataController() + "/getChild/" + id,
            type: "get",
            success: function (data) {
                //              console.log(data)
                editProvince(data.belongtoProvince, data.belongtoCity, data.belongtoArea);
                if (status == 2) {
                    $('#unapproval_reason').show();
                    $("#reason").val(data.checkOpinion);
                }
                if (type == 0) {
                    data.cwmgj = data.cwmgj.split(",");
                    Tool.deserialize("brickForm", data);
                    $('#cwmgj').selectpicker('val', data.cwmgj);
                    viewFileUpload(data.detailFile);
                } else if (type == 1) {
                    data.cwmgj = data.cwmgj.split(",");
                    Tool.deserialize("concreteForm", data);
                    $('#cwmgj').selectpicker('val', data.cwmgj);
                    viewFileUpload(data.detailFile);
                } else if (type == 2) {
                    Tool.deserialize("highStructureForm", data);
                    viewFileUpload(data.detailFile);
                } else if (type == 3) {
                    Tool.deserialize("factoryForm", data);
                    viewFileUpload(data.detailFile);
                } else if (type == 4) {
                    Tool.deserialize("wideStructureForm", data);
                    viewFileUpload(data.detailFile);
                } else if (type == 5) {
                    Tool.deserialize("buildingForm", data);
                    viewFileUpload(data.detailFile);
                } else if (type == 6) {
                    Tool.deserialize("woodForm", data);
                    viewFileUpload(data.detailFile);
                } else if (type == 7) {
                    Tool.deserialize("stoneForm", data);
                    viewFileUpload(data.detailFile);
                } else if (type == 8) {
                    Tool.deserialize("otherForm", data);
                    viewFileUpload(data.detailFile);
                }else if (type == 9) {
                    data.cwmgj = data.cwmgj.split(",");
                    Tool.deserialize("brickwoodForm", data);
                    $('#cwmgj').selectpicker('val', data.cwmgj);
                    viewFileUpload(data.detailFile);
                } 

            }
        });
    }
    var editProvince = function (Province, City, Area) {
        var html = "";
        $("#belongtoCity").append(html);
        $("#belongtoArea").append(html);
        $.ajax({
            url: "/app/divisions/root/subdivisions",
            contentType: "application/json",
            type: "get",
            success: function (data) {
                $.each(data, function (idx, item) {
                    if (item.divisionName == Province) {
                        var divisionId = item.divisionId;
                        var htmlCity = '';
                        if (Province == "北京市" || Province == "天津市" || Province == "上海市" || Province == "重庆市") {
                            $("#belongtoCity").append("<option value='" + Province + "' exid='" + divisionId + "'>" + Province + "</option>");
                            $('#belongtoCity').val(City);
                            var htmlArea = '';
                            $.ajax({
                                url: "/app/divisions/" + divisionId + "/subdivisions",
                                contentType: "application/json",
                                type: "get",
                                success: function (data) {
                                    $.each(data, function (idx, item) {
                                        htmlArea += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                                    });
                                    $("#belongtoArea").append(htmlArea);
                                    $('#belongtoArea').val(Area);
                                }
                            });

                        } else {
                            $.ajax({
                                url: "/app/divisions/" + divisionId + "/subdivisions",
                                contentType: "application/json",
                                type: "get",
                                success: function (data) {
                                    $.each(data, function (idx, item) {
                                        if (item.divisionName == City) {
                                            var divisionId = item.divisionId;
                                            var htmlArea = '';
                                            $.ajax({
                                                url: "/app/divisions/" + divisionId + "/subdivisions",
                                                contentType: "application/json",
                                                type: "get",
                                                success: function (data) {
                                                    $.each(data, function (idx, item) {
                                                        htmlArea += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                                                    });
                                                    $("#belongtoArea").append(htmlArea);
                                                    $('#belongtoArea').val(Area);
                                                }
                                            });
                                        }
                                        htmlCity += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                                    });
                                    $("#belongtoCity").append(htmlCity);
                                    $('#belongtoCity').val(City);
                                }
                            });
                        }
                    }
                    html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                });
                $("#belongtoProvince").append(html);
                $('#belongtoProvince').val(Province);
            }
        });
        $("#belongtoProvince").change(function () {
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#belongtoCity option").remove();
            $("#belongtoCity").append(html);
            $("#belongtoArea option").remove();
            $("#belongtoArea").append(html);
            var divisionId = $(this).find("option:selected").attr("exid");
            if ($(this).val() == "北京市" || $(this).val() == "天津市" || $(this).val() == "上海市" || $(this).val() == "重庆市") {
                $("#belongtoCity").append("<option value='" + $(this).val() + "' exid='" + divisionId + "'>" + $(this).val() + "</option>");
                return;
            }
            $.ajax({
                url: "/app/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#belongtoCity").append(html);
                }
            });
        });
        $("#belongtoCity").change(function () {
            if ($(this).val() == "") return;
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#belongtoArea option").remove();
            $("#belongtoArea").append(html);
            var divisionId = $(this).find("option:selected").attr("exid");
            $.ajax({
                url: "/app/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#belongtoArea").append(html);
                }
            });
        });
    }
    // 判断打开那个表单--查看表单
    var openForm = function (type) {
        var openform;
        if (type == '0') {
            // 砖混结构
            openform = sysPath + "/siftdata/views/brickForm.html";
        } else if (type == '1') {
            // 多层钢筋混凝土结构
            openform = sysPath + "/siftdata/views/concreteForm.html";
        } else if (type == '2') {
            // 高层结构
            openform = sysPath + "/siftdata/views/highStructureForm.html";
        } else if (type == '3') {
            // 工业厂房结构
            openform = sysPath + "/siftdata/views/factoryForm.html";
        } else if (type == '4') {
            // 空旷结构
            openform = sysPath + "/siftdata/views/wideStructureForm.html";
        } else if (type == '5') {
            // 土木结构
            openform = sysPath + "/siftdata/views/buildingForm.html";
        } else if (type == '6') {
            // 木结构
            openform = sysPath + "/siftdata/views/woodForm.html";
        } else if (type == '7') {
            // 石结构
            openform = sysPath + "/siftdata/views/stoneForm.html";
        } else if (type == '8') {
            // 其它
            openform = sysPath + "/siftdata/views/otherForm.html";
        } else if (type == '9') {
            // 砖木结构
            openform = sysPath + "/siftdata/views/brickwoodForm.html";
        }
        return openform;
    }

    // 判断打开那个表单--审核
    var openCheckForm = function (type) {
        var opencheckform;
        if (type == '0') {
            // 砖混结构
            opencheckform = sysPath + "/siftdata/views/brickCheckForm.html";
        } else if (type == '1') {
            // 多层钢筋混凝土结构
            opencheckform = sysPath + "/siftdata/views/concreteCheckForm.html";
        } else if (type == '2') {
            // 高层结构
            opencheckform = sysPath + "/siftdata/views/highStructureCheckForm.html";
        } else if (type == '3') {
            // 工业厂房结构
            opencheckform = sysPath + "/siftdata/views/factoryCheckForm.html";
        } else if (type == '4') {
            // 空旷结构
            opencheckform = sysPath + "/siftdata/views/wideStructureCheckForm.html";
        } else if (type == '5') {
            // 土木结构
            opencheckform = sysPath + "/siftdata/views/buildingCheckForm.html";
        } else if (type == '6') {
            // 木结构
            opencheckform = sysPath + "/siftdata/views/woodCheckForm.html";
        } else if (type == '7') {
            // 石结构
            opencheckform = sysPath + "/siftdata/views/stoneCheckForm.html";
        } else if (type == '8') {
            // 石结构
            opencheckform = sysPath + "/siftdata/views/otherCheckForm.html";
        } else if (type == '9') {
            // 砖木结构
            opencheckform = sysPath + "/siftdata/views/brickwoodCheckForm.html";
        }
        return opencheckform;
    }

    // 初始化加载搜索框内容
    var initSearchForm = function () {
        //初始化行政岗区划
        var combotree = Combotree({
            // combo组件相关配置
            combo: {
                //要渲染的input的id
                id: "region",
                //下拉框的类型：单选or多选
                multi: false,
                key: {
                    idKey: "divisionId",
                    textKey: "divisionName"
                },
                //          placeholder: "请选择……",
                event: {
                    onShowPanel: function () {
                        console.log("show");
                    },
                    onHidePanel: function () {
                        console.log("hide");
                    },
                    onChange: function (n, o) {
                        $("#regionId").val(n[0].divisionId);
                        $("#region").val(n[0].divisionName);
                    }
                }
            },
            // ztree组件相关配置
            ztree: {
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "divisionId", // 主键属性名
                        pIdKey: "parentId" // 父节点属性名
                    },
                    key: {
                        name: "divisionName" // 显示名称属性名
                    }
                },
                check: {
                    chkboxType: {
                        'Y': '',
                        'N': ''
                    }
                }
            },
            data: {
                url: getDivisionController() + 'initDivisionZtree',
                type: 'GET',
                success: function () {

                }
            },
            formatter: function (node) {
                node.open = true;
            },
            value: $("#divisionId").val(),
            search: {
                enable: true,
                fields: ["divisionName"]
            }
        });
    }

    return {
        init: init
    };
});